/***************************************************************************
 *  Filename: simplecommunicationhandler.h
 *  Class: SimpleCommunicationHandler
 *  
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SIMPLECOMMUNICATIONHANDLER_H
#define SIMPLECOMMUNICATIONHANDLER_H

#include <QObject>
#include <qextserialport/qextserialport.h>
#include <QDataStream>

#include "uartmessages.h"

class SimpleCommunicationHandler : public QObject
{
    Q_OBJECT
public:
    explicit SimpleCommunicationHandler(QObject *parent = 0);
    void setupPort();
    void sendData(QByteArray data);
signals:
    void takeOff();
    void land();
    void emergency();
    void reset();
    void relativeTarget(float x, float y, int altitude, float yaw);
    void gpsTarget(float latitude, float longitude, int altitude);
    void updateGpsPosition(float latitude, float longitude, float altitude);
    void trim();
public slots:
    void sendVelocity(float vx, float vy, float vz);
    void sendGyros(float roll, float pitch, float yaw);
    void sendBattery(int perc);
    void sendAltitude(int altitude);

private slots:
    void getData();
    void getDataA();

private:
    QextSerialPort serial;
    QByteArray buffer;
    quint32 lastSequenceReceived;
    quint32 lastSequenceSent;
    bool receiving;
};

#endif // SIMPLECOMMUNICATIONHANDLER_H
